﻿namespace FeatureRequestExample
{
    using System;
    using System.Linq;
    using Stateless;

    public class Feature    
    {
        enum State { Requested, Approved, Tested, Deployed }
        enum Trigger { Assign, Program, Test, Deploy }

        StateMachine<State, Trigger, Request> StateMachine { get; set; }
        State state = State.Requested;

        public Feature(Request request)
        {
            this.StateMachine = new StateMachine<State, Trigger, Request>(state);
            var requested = this.StateMachine.Configure(State.Requested)
                .Permit(Trigger.Assign,State.Approved);
            var approved = this.StateMachine.Configure(State.Approved);

            approved.OnEntryFrom(Trigger.Assign, (t, r) =>
                {
                    System.Diagnostics.Debug.WriteLine("Entering from Assign");
                });
             approved.OnEntry((t, r) =>
                {
                    System.Diagnostics.Debug.WriteLine("Entering Assigned");
                });
             approved.OnExit((t, r) =>
                {
                    System.Diagnostics.Debug.WriteLine("Leaving Assigned");
                });
            requested.OnEntryFrom(Trigger.Assign, (t, r) =>
                {
                    System.Diagnostics.Debug.WriteLine("Entering from Assign");
                });
           
            requested.OnEntry((t, r) =>
                {
                    System.Diagnostics.Debug.WriteLine("Entering Assigned");
                });
           
            requested.OnExit((t, r) =>
                {
                    System.Diagnostics.Debug.WriteLine("Leaving Assigned");
                });

            StateMachine.Fire(Trigger.Assign, request);
        }
       
        
    }

    public class Request
    {
        public string Name { get; set; }
        public string Description { get; set; }
        public string RequestedBy { get; set; }
    }
}